home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d10 / rem23.arc / E2O.C next >
Text File  |  1991-02-19  |  2KB  |  54 lines

  1. /***************************************************************/
  2. /*                                                             */
  3. /*  E2O.C                                                      */
  4. /*                                                             */
  5. /*  Redirect stderr to stdout.                                 */
  6. /*                                                             */
  7. /*  (C) 1990 by David Skoll.                                   */
  8. /*                                                             */
  9. /***************************************************************/
  10. #include <io.h>
  11. #include <stdio.h>
  12. #include <process.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15.  
  16. char buf[40];
  17.  
  18. main(int argc, char *argv[], char *env[])
  19. {
  20.    char *s, *s1;
  21.    int save_err = dup(fileno(stderr));
  22.  
  23.    if (argc == 1) {
  24.       fprintf(stderr, "Usage: E2O program [args]\n");
  25.       exit(1);
  26.    } 
  27.  
  28.    /* Force stderr to be stdout */
  29.    if (dup2(fileno(stdout), fileno(stderr)) == -1 ) {
  30.       fprintf(stderr, "Can't redirect stderr!\n");
  31.       exit(1);
  32.    }
  33.    strcpy(buf, argv[1]);
  34.  
  35.    s = strrchr(buf, '.');
  36.    s1 = strrchr(buf, '\\');
  37.    if (s1 != NULL && s < s1) s = NULL;
  38.  
  39.    /* Try .COM first */
  40.    if (s == NULL) strcat(buf, ".COM");
  41.    execvpe(buf, &argv[1], env);
  42.  
  43.    /* If we got here, it didn't work... try .EXE */
  44.    if (s == NULL) {
  45.       strcpy(buf, argv[1]);
  46.       strcat(buf, ".EXE");
  47.       execvpe(buf, &argv[1], env);
  48.    }
  49.  
  50.    /* Die here */
  51.    dup2(save_err, fileno(stderr));
  52.    fprintf(stderr, "Can't exec %s.\n", argv[1]);
  53.    exit(1);
  54. }